﻿@model Sealight.Core.DataAdapter.product_attribute
@{
    ViewBag.Title = "_AddUpdateProductAttribute";
    Layout = "~/Areas/Admin/Views/Shared/__AdminLayout.cshtml";
    string name = string.Empty, description = string.Empty, id=string.Empty;
    if(Model != null)
    {
        name = Model.name; description = Model.description; id = Model.id.ToString();
    }
}
@section _Head{
<script language="javascript" type="text/javascript">

    $(document).ready(function () {
        var container = $('div.container_error');
        $("#data_form").validate({
            rules: {
                name_field: {// compound rule 
                    required: true
                }
            },
            messages: {
                name_field: {
                    required: "Vui lòng nhập tên."
                }
            },
            errorElement: "li",
            errorContainer: container,
            errorLabelContainer: $(".error", container)
            ,
            submitHandler: function (form) {               
                var data = {
                    id: $("#product_attribute_id").val(),
                    name: $("#name_field").val(),
                    description: $("#description_field").val()
                }; 
                $.ajax({
                    type: "POST",
                    url: "/admin/product/SaveProductAttributeData",
                    data: JSON.stringify(data),
                    traditional: true,
                    dataType: "json",
                    contentType: 'application/json',
                    error: function (xhr, status, error) { },
                    success: function (d) {
                        if (d != null) {
                            if (d.OperationComplete != null && d.OperationComplete == false && d.ErrorCode != null) {
                                if (d.ErrorFriendlyMessage != null) {
                                    ShowErrorMessage(d.ErrorFriendlyMessage);
                                }
                                return;
                            }
                            else {
                                ShowErrorMessage("Lưu thành công", "thông báo");
                                $('#data_form').get(0).reset();
                            }
                        }
                    },
                    complete: function (d) {
                    },
                    cache: false
                }); //end .ajax call
            }
        }); //end form.validate       
    });
</script>
}
@if (Model == null)
{
<h2>Thêm mới thuộc tính sản phẩm
</h2>
}
else
{
<h2>Sửa thuộc tính sản phẩm
</h2>
}
<form id="data_form" method="post" action="" enctype="multipart/form-data">
<div class="options">
    <input type="submit"   value="Lưu" id="btnAddNew" class="adminButtonBlue" title="Lưu thuộc tính cho sản phẩm">
</div>
<div class="container_error">
    <h5>
        Vui lòng kiểm tra lại các lỗi...</h5>
    <ol class="error">
    </ol>
</div>
<table class="adminContent">
    <tbody>
        <tr>
            <td class="adminTitle">
                <span id="" title="The name of the product attribute.">Name:</span>
            </td>
            <td class="adminData">
                <input name="name_field" type="text" id="name_field" class="adminInput" value="@name">               
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                <span id="" title="The product attribute description.">Description:</span>
            </td>
            <td class="adminData">
                <textarea name="" rows="2" cols="20" id="description_field" name="description_field"
                    class="adminInput" style="height: 100px;">@description</textarea>
            </td>
        </tr>
    </tbody>
</table>
<input type="hidden" id="product_attribute_id" name="product_attribute_id" value="@id" />
</form>
